package com.sgb.merchant.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.databinding.DataBindingUtil;

import com.sgb.link.entity.merchant.EnrolInfoEntiy;
import com.sgb.merchant.R;
import com.sgb.merchant.databinding.MerchantDialogApplyRoundBinding;
import com.swgk.core.util.DateUtils;


/**
 * 圆角提示弹窗Dialog
 */
public class ApplyDialog extends Dialog implements View.OnClickListener {
    private MerchantDialogApplyRoundBinding mBinding;
    private EnrolInfoEntiy mEntity;

    public ApplyDialog(Context context, EnrolInfoEntiy entity) {
        super(context, R.style.RoundCornerDialog);
        mEntity = entity;
        mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.merchant_dialog_apply_round, null, false);
        setContentView(mBinding.getRoot());
        init();
        //
        Window window = getWindow();
        if (window != null) {
            WindowManager.LayoutParams params = window.getAttributes();
            params.gravity = Gravity.CENTER;
            window.setAttributes(params);
        }
    }

    private void init() {
        mBinding.tvConfirm.setOnClickListener(this);
        mBinding.fileDownload.setOnClickListener(this);
        mBinding.tvName.setText(mEntity.getTenantName());
        mBinding.tvTimes.setText(DateUtils.stampToDay6(mEntity.getCreateTime()));
        mBinding.tvPerson.setText(mEntity.getLinkName());
        mBinding.tvAddress.setText(mEntity.getAddressInfo());
        mBinding.tvTel.setText(mEntity.getLinkPhone());
        mBinding.tvMoney.setText(mEntity.getInvestmentBudget());
        switch (mEntity.getApplyUtype()) {//（0个人 1企业 2团队 3组织）
            case 0:
                mBinding.tvType.setText("个人");
                break;
            case 1:
                mBinding.tvType.setText("企业");
                break;
            case 2:
                mBinding.tvType.setText("团队");
                break;
            case 3:
                mBinding.tvType.setText("组织");
                break;
        }
        if(TextUtils.isEmpty(mEntity.getFileName())){
            mBinding.fileName.setVisibility(View.GONE);
            mBinding.title6.setVisibility(View.GONE);
            mBinding.fileDownload.setVisibility(View.GONE);
        }else{
            mBinding.fileName.setText(mEntity.getFileName());
        }
    }




    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_confirm) {
            dismiss();
        }else if(id==R.id.file_download){
            Uri uri = Uri.parse(mEntity.getFileUrl());
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            getContext().startActivity(intent);
        }
    }
}
